<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>预约</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css"
          th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}">
    </script>
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>

<body>
<form name="reverseForm" id="reverseForm" method="post" style="width:50%; margin:0
    auto">
    <h2 style="text-align:center; margin-bottom: 20px">预约场地</h2>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">Cookie</label>
            <div class="col-md-5">
                <input id="cookie" name="cookie" class="form-control"
                       type="text" placeholder="乐约Cookie" required/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">Cookie</label>
            <div class="col-md-5">
                <select id="court" name="court" class="form-control" required>
                    <option value="5982" selected="selected">一楼球场</option>
                    <option value="5991">三楼球场</option>
                </select>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">预约时间段1</label>
            <div class="col-md-5">
                <input id="timeslot1" name="timeslot1" class="form-control"
                       type="text" placeholder="预约的第一个时间段" required/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">预约时间段2（非必填）</label>
            <div class="col-md-5">
                <input id="timeslot2" name="timeslot2" class="form-control"
                       type="text" placeholder="预约的第二个时间段"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">手机号码（非必填）</label>
            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control"
                       type="text" placeholder="接受预约信息的手机号码"
                       minlength="11" maxlength="11"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="submit"
                    onclick="reverse()">定时抢下一场
            </button>
        </div>
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="submit"
                    onclick="reverseOnToday()">直接定这一场
            </button>
        </div>
    </div>
    <div class="row">
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="reset"
                    onclick="reset()">重新输入
            </button>
        </div>
    </div>

</form>
</body>
<script>
    function reverse() {
        $("#reverseForm").validate({
            submitHandler: function () {
                doReverse();
            }
        });
    }

    function doReverse() {
        g_showLoading();
        $.ajax({
            url: "/reverse/badminton",
            type: "GET",
            data: {
                "court": $("select[name='court'] option:selected").val(),
                "cookie": $("#cookie").val(),
                "time\-slot1": $("#timeslot1").val(),
                "time\-slot2": $("#timeslot2").val(),
                "phone": $("#mobile").val()
            },
            dataType: "json",
            success: function (data) {
                layer.closeAll();
                if (data.code === 200) {
                    layer.msg(data.data);
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }

    function reverseOnToday() {
        $("#reverseForm").validate({
            submitHandler: function () {
                doReverseOnToday();
            }
        });
    }

    function doReverseOnToday() {
        g_showLoading();
        $.ajax({
            url: "/reverse/badmintonToday",
            type: "GET",
            data: {
                "court": $("select[name='court'] option:selected").val(),
                "cookie": $("#cookie").val(),
                "time\-slot1": $("#timeslot1").val(),
                "time\-slot2": $("#timeslot2").val(),
                "phone": $("#mobile").val()
            },
            dataType: "json",
            success: function (data) {
                layer.closeAll();
                if (data.code === 200) {
                    layer.msg(data.data);
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</html>